package com.gqr.lock.reentrantlock;

import java.util.concurrent.locks.ReentrantLock;

/**
 * Copyright (C), 2020-2024,gqr
 * FileName:CinemaBookSeat
 * author:guqingrong
 * Date:2024-05-10 21:58
 * Description:演示多线程预定电影院座位
 * History:
 * <author>    <time>    <version>    <desc>
 * 作者姓名     修改时间     版本号        描述
 */
public class CinemaBookSeat {
    private static ReentrantLock lock = new ReentrantLock();
    private static void bookSeat(){
        lock.lock();
        try {
            System.out.println(Thread.currentThread().getName()+"开始预定座位");
            Thread.sleep(1000);
            System.out.println(Thread.currentThread().getName()+"完成预定座位");

        } catch (InterruptedException e) {
            e.printStackTrace();
        } finally {
            lock.unlock();
        }
    }

    public static void main(String[] args) {
        new Thread(CinemaBookSeat::bookSeat).start();
        new Thread(CinemaBookSeat::bookSeat).start();
        new Thread(CinemaBookSeat::bookSeat).start();
        new Thread(CinemaBookSeat::bookSeat).start();
    }
}
